package com.heima.crm.controller;

import com.heima.crm.common.result.PageResult;
import com.heima.crm.common.result.Result;
import com.heima.crm.pojos.dtos.*;
import com.heima.crm.pojos.entity.TbClue;
import com.heima.crm.pojos.entity.TbClueFollow;
import com.heima.crm.service.ClueService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/clue")
public class ClueController {

    @Autowired
    private ClueService clueService;



    /**
     * 线索批量导入
     * @param multipartFile
     * @return
     */
    @PostMapping("/loadFile")
    public Result loadFile(MultipartFile multipartFile){
        log.info("线索批量导入，文件解析：{}",multipartFile);
        return clueService.loadFile(multipartFile);
    }

    @DeleteMapping("/deleteClueByIds")
    public Result deleteClueByIds(@RequestParam List<Long> ids){
        log.info("删除线索：{}",ids);
        return clueService.deleteClueByIds(ids);
    }

    /**
     * 新增线索
     * @param tbClue
     * @return
     */
    @PostMapping("/newClue")
    public Result newClue(@RequestBody TbClue tbClue){
        log.info("新增线索接收参数：{}",tbClue);
        return clueService.newClue(tbClue);
    }

    /**
     * 分页查询
     * @return
     */
    @GetMapping("/listClue")
    public Result cluePage(CluePageDto cluePageDto){
        log.info("线索分页查询:{}",cluePageDto);
        return clueService.cluePage(cluePageDto);
    }

    /**
     * 分配线索
     * @param dto
     * @return
     */
    @PostMapping("/clueDistribute")
    public Result distribute(@RequestBody ClueDistributeDto dto){
        log.info("线索分配：{}",dto);
        return clueService.distribute(dto);
    }

    /**
     * 跟进 线索数据回显
     * @param id
     * @return
     */
    @GetMapping("/follow/{id}")
    public Result followClue(@PathVariable Long id){
        log.info("线索数据回显：{}",id);
        return clueService.followClue(id);
    }



    /**
     * 新增线索跟进
     * @param dto
     * @return
     */
    @PostMapping("/follow/save")
    public Result saveFollowClue(@RequestBody ClueFollowDto dto){
        log.info("新增跟进：{}",dto);
        return clueService.saveFollowClue(dto);
    }


    /**
     * 提交伪线索
     * @param dto
     * @return
     */
    @PostMapping("/follow/fakeClue")
    public Result fakeClue(@RequestBody ClueFakeDto dto){
        log.info("提交伪线索：{}",dto);
        return clueService.fakeClue(dto);
    }

    /**
     * 线索转商机
     * @param id
     * @return
     */
    @GetMapping("/follow/business/{id}")
    public Result clueToBusiness(@PathVariable Long id){
        log.info("转商机：{}",id);
        return clueService.clueToBusiness(id);
    }


    /**
     * 线索池分页查询
     * @param cluePoolPageDto
     * @return
     */
    @GetMapping("/clue_pool/listCluePool")
    public Result cluePoolList( CluePoolPageDto cluePoolPageDto){
        log.info("线索池分页查询：{}",cluePoolPageDto);
        return clueService.cluePoolList(cluePoolPageDto);
    }


    /**
     * 捞取线索
     * @param id
     * @return
     */
    @GetMapping("/clue_pool/fish/{id}")
    public Result clueFish(@PathVariable Long id){
        log.info("线索捞取：{}",id);
        return clueService.clueFish(id);
    }

    /**
     * 批量捞取线索
     * @param ids
     * @return
     */
    @PostMapping("/clue_pool/fish")
    public Result clueFishByIds(@RequestParam List<Long> ids){
        log.info("批量捞取线索：{}",ids);
        return clueService.clueFishByIds(ids);
    }
}
